<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>功能室审批-云校通</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
</head>
<body ontouchstart style="background: #fff;">
<div class="weui_tab tab-bottom">
	<div class="weui-header bg-blue"> 
  		<div class="weui-header-left"> <a onclick="back()" href="javascript:" class="icon icon-109 f-white">返回</a> </div>
    	<h1 class="weui-header-title">功能室占用查询</h1>
    </div>
	<div class="weui_tab_bd">
		<div class="weui_cells weui_cells_access" style="margin-top: 0px;">
       		<div class="weui_cell weui_cell_select weui_select_after">
				<div class="weui_cell_hd">
					<label class="weui_label">场室名称</label>
				</div>
                <div class="weui_cell_bd weui_cell_primary">
                    <select class="weui_select" id="roomName" name="roomName">
                        <option value="">请选择</option>
                    </select>
                </div>
            </div>
            <div class="weui_cell">
				<div class="weui_cell_hd">
					<label class="weui_label">使用日期</label>
				</div>
                <div class="weui_cell_bd weui_cell_primary">
               		<input id="useDate" name="useDate" type="text" class="weui_input" placeholder="请输入使用日期"/>
           		</div>
            </div>
            <div class="weui_cell"></div>
            <div class="weui_btn_area">
		        <a href="javascript:" style="width: 40%;" class="weui_btn bg-blue" id="querySubmit">查询</a>
		    </div>
        </div>
		
		<div id="roomList"></div>
	</div>
</div>
<script src="<%=basePath %>/js/picker.js"></script>
<script type="text/javascript">
	initFunctionRoom();
	$("#useDate").datetimePicker({title:"选择使用日期",m:1});
	$("#querySubmit").click(function() {
		querySubmit();
	})
	function querySubmit() {
		var roomName = $("#roomName").val();
		if(roomName.length == 0) {
			$.alert("请选择功能室!","");
			return;
		}
		var useDate = $("#useDate").val();
		if(useDate.length == 0) {
			$.alert("请选择使用日期!","");
			return;
		}
		$.ajax({
			url: basePath + '/ls/function/room/getAuditSuccessListByDate',
			type: 'post',
			dataType: 'json',
			data: {
				roomName: roomName,
				useDate: useDate
			},
			success: function(data) {
				var html = '<div class="weui_cells"><div class="weui_cell lblue tz-history-title">功能室占用列表</div>';
				for(var i in data) {
					var itm = data[i];
					html += '<div class="weui_cell weui_media_box weui_media_text">\
						<div class="weui_cell_bd weui_cell_primary">\
							<h4 class="weui_media_title">申请人：'+itm.applyer+'</h4>\
							<p class="weui_media_desc">使用时段：'+lessonText(itm.applyLesson)+'</p>\
							<p class="weui_media_desc">使用事由：'+itm.useReason+'</p>\
							<p class="weui_media_desc">状态：'+itm.statusText+'</p>\
							<p class="weui_media_desc">审批人：'+itm.approver+'</p>\
							<p class="weui_media_desc">申请时间：'+getTime(itm.useDate, "yyyy年MM月dd日")+'</p>\
						</div>\
					</div>';
				}
				html += "</div>";
				$("#roomList").html(html);
			},
            error: function(xhr, type){
            	$.toptips("系统异常");
            }
		});
	}
	function lessonText(lesson) {
		var array = [];
		var lessons = lesson.split(',');
		for(var i in lessons) {
			if(parseInt(lessons[i]) == 9) array.push("晚修一");
			else if(parseInt(lessons[i]) == 10) array.push("晚修二");
			else array.push("第" + lessons[i] + "节");
		}
		return array.toString();
	}
	function initFunctionRoom() {
		$.ajax({
			url: basePath + '/dictData/dictCode',
			type: 'post',
			dataType: 'json',
			data: {
				dictCode: "function_room"
			},
			success: function(data) {
				if(data != null && data.length > 0) {
					var html = '';
					for(var i in data) {
						html += '<option value="'+data[i].dictDataValue+'">'+data[i].dictDataValue+'</option>';
					}
					$("#roomName").append(html);
				}
			},
            error: function(xhr, type){
            	$.toptips("系统异常");
            }
		});
	}
</script>
</body>
</html>